package de.jmda.gen.java.impl;

import static org.junit.Assert.assertTrue;

import org.apache.log4j.Logger;
import org.junit.Test;

import de.jmda.gen.GeneratorException;
import de.jmda.gen.java.CompilationUnitPackageInfoGenerator;
import de.jmda.gen.java.DeclaredPackageGenerator;
import de.jmda.gen.java.PackageStatementGenerator;

public class JUTDefaultPackageDeclarationGenerator
{
	private final static Logger LOGGER =
      Logger.getLogger(JUTDefaultPackageDeclarationGenerator.class);

	@Test
	public void testDefaultPackageDeclarationGenerator()
			throws GeneratorException
	{
		CompilationUnitPackageInfoGenerator generator =
				new DefaultPackageInfoGenerator();

//		GeneratorValidation.validate(generator);

		StringBuffer generated = generator.generate();

		LOGGER.debug("generated [" + generated + "]");

		assertTrue(
				"unexpected package declaration [" + generated + "]",
				(
						"package " +
						DefaultPackageStatementGenerator.DEFAULT_PACKAGE_NAME + ";"
				).contentEquals(generated));
	}

	@Test
	public void testDefaultPackageDeclarationGeneratorWithJavaDoc()
			throws GeneratorException
	{
		CompilationUnitPackageInfoGenerator generator =
				new DefaultPackageInfoGenerator();
		
		generator.setJavaDocGenerator(new DefaultJavaDocGenerator());

//		GeneratorValidation.validate(generator);

		StringBuffer generated = generator.generate();

		LOGGER.debug("generated [" + generated + "]");

		assertTrue(
				"unexpected package declaration [" + generated + "]",
				(
						"/**" + System.lineSeparator() +
						" */" + System.lineSeparator() +
						"package " +
						DefaultPackageStatementGenerator.DEFAULT_PACKAGE_NAME + ";"
				).contentEquals(generated));
	}

	@Test
	public void testDefaultPackageDeclarationGeneratorWithPackageStatementGenerator()
			throws GeneratorException
	{
		String input = "test";

		PackageStatementGenerator packageStatementGenerator =
				new DefaultPackageStatementGenerator(input);

		DeclaredPackageGenerator declaredPackageGenerator =
				new DefaultDeclaredPackageGenerator(packageStatementGenerator);

		// TODO create constructor that takes input as parameter
		CompilationUnitPackageInfoGenerator generator =
				new DefaultPackageInfoGenerator(declaredPackageGenerator);

		StringBuffer generated = generator.generate();

		LOGGER.debug("generated [" + generated + "]");

		assertTrue(
				"unexpected package declaration [" + generated + "]",
				("package " + input + ";").contentEquals(generated));
	}
}